package org.base.common.util;

import java.util.Random;

/**
 * @author He mingliang
 * @date 2020/7/13
 */
public class RandomUtils {

    private static final String ALL_CHAR = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";


    /**
     * 随机字符串
     * @param length
     * @return
     */
    public static String generateString(int length) {
        StringBuffer sb = new StringBuffer();
        Random random = new Random();
        for (int i = 0; i < length; i++) {
            sb.append(ALL_CHAR.charAt(random.nextInt(ALL_CHAR.length())));
        }
        return sb.toString();
    }

    public static int generateInt(int length) {
        int base = 1;
        int max = 0;
        for (int i = 0; i < length - 1; i++) {
            base *= 10;
        }
        max = base * 9;
        Random random = new Random();
        return random.nextInt(max) + base;
    }

    public static void main(String[] args) {
        for (int i = 0; i < 1000; i++) {
            System.out.println(generateInt(6));
        }
//        for (int i = 0; i < 1000000000; i++) {
//            System.out.println(generateString(6));
//        }
    }
}
